Dim ActiveCmd
ActiveCmd = "3"

Dim Shell, fullPath, regValue,valueType  
Set Shell = CreateObject("WScript.Shell")

fullPath = "HKEY_CURRENT_USER\Software\MyApp"	
valueName="PADS_SHORTCUTS_ROOT"
Dim root
root = Shell.RegRead(fullPath & "\" & valueName)


If root ="" Then 
	MsgBox "please set env value (PADS_SHORTCUTS_ROOT = ?)"
ELSE	
	Dim folderPath, fileNamePattern, fso, folder, file, found, matches
	folderPath = root & "\skill\B"
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set folder = fso.GetFolder(folderPath)

	fullPath = "HKEY_CURRENT_USER\Software\MyApp"	
	valueName="PADS_Command"
	valueType = "REG_SZ"

	Dim cmdparam 
	cmdparam = Shell.RegRead(fullPath & "\" & valueName)
	if cmdparam="" then
		dim ws : set ws = CreateObject("WScript.Shell")
		dim varName : varName = "ActiveLayerOnly"
		dim regPath : regPath ="HKEY_CURRENT_USER\Software\MyApp\PADS\" & varName
		dim varValue : varValue = ws.RegRead(regPath)
		Application.StatusBarText =""


		dim plyr,clyr
		'plyr =ws.RegRead("HKEY_CURRENT_USER\Software\MyApp\PADS\PreviousLayer")
		clyr =ws.RegRead("HKEY_CURRENT_USER\Software\MyApp\PADS\CurrentLayer")
		plyr = cint(clyr)	
		clyr = 3
		ws.RegWrite "HKEY_CURRENT_USER\Software\MyApp\PADS\PreviousLayer", plyr, "REG_EXPAND_SZ"
		ws.RegWrite "HKEY_CURRENT_USER\Software\MyApp\PADS\CurrentLayer", clyr, "REG_EXPAND_SZ"
		dim slyr,elyr
		slyr=-1
		elyr=-1
		if plyr=-1 then
		else
			if plyr>clyr then
				slyr = clyr
				elyr = plyr			
			else
				slyr = plyr
				elyr = clyr
			end if
		end if
		if application.version=5.3 then
			Application.ModelessCommand("L")
			DlgModelessCmd.Command = "L 3"
			DlgModelessCmd.OnOk()
		else	
			select case varValue
				case 0
					Application.ModelessCommand("z")
					DlgModelessCmd.Command = "z e"
					DlgModelessCmd.OnOk()			
				case 1
					Application.ModelessCommand("z")
					DlgModelessCmd.Command = "z 3"
					DlgModelessCmd.OnOk()
			end select	
			Application.ModelessCommand("L")
			DlgModelessCmd.Command = "L 3"
			DlgModelessCmd.OnOk()
			'add via to route
			dim ocmd			
			ocmd = ""
			if slyr<>elyr then
				if slyr=-1 and elyr=-1 then
				else
					ocmd = "pl " &  slyr & " " & elyr
					'sgbox ocmd
					Application.ModelessCommand("p")
					DlgModelessCmd.Command =ocmd
					DlgModelessCmd.OnOk()
					dim doc,v
					set doc = applition.activedocument
					set v = doc.activeview
					
					'Application.ExecuteCommand("Add Via To Route", -731.09226mil, -2622.18738mil)
					dim unit,unit_str
					unit = doc.Unit
					select case unit
						case 2'mil
							unit_str = "mil"
							Application.ExecuteCommand("Add Via To Route", v.PointerX & "mil", v.PointerY & "mil")
						case 4'mm
							unit_str = "mm"
							Application.ExecuteCommand("Add Via To Route", v.PointerX & "mm", v.PointerY & "mm")
						case else
							'msgbox "please switch units to mm or mils"
							'exit sub
					end select		
				end if	
			end if
			if doc.ElectricalLayerCount=3 then
				Application.ModelessCommand("l b")
			else
				'MainFrame.StandardToolbarCurrentLayer = "(V) L3"
				'MainFrame.StandardToolbarCurrentLayer = "(H) L3"
				Application.ModelessCommand("l 3")
			end if
		end if
		set ws = nothing	
	else
		cmdparam = cmdparam & ActiveCmd
		cmdparam = LCase(cmdparam)
		'msgbox cmdparam
		fileNamePattern = cmdparam & ".mcr"
		For Each file In folder.Files
			If LCase(file.Name) = LCase(fileNamePattern) Then
				Application.RunMacro(file.path,"")
				cmdparam =""
				Exit For
			End If
		Next

		If Len(cmdparam)>2 Then cmdparam=ActiveCmd
		Shell.RegWrite fullPath & "\", "", "REG_SZ"
		Shell.RegWrite fullPath & "\" & valueName, valueData, valueType
	end if
End If
